/*===================================================================*/
/*                                                                   */
/*  K6502.h : Header file for K6502                                  */
/*                                                                   */
/*  2000/05/29  InfoNES Project ( based on pNesX )                   */
/*                                                                   */
/*===================================================================*/

#ifndef K6502_H_INCLUDED
#define K6502_H_INCLUDED

#ifdef	__cplusplus
extern	"C"{
#endif
// Type definition
#ifndef DWORD
typedef unsigned long  DWORD;
#endif

#ifndef WORD
typedef unsigned short WORD;
#endif

#ifndef BYTE
typedef unsigned char  BYTE;
#endif

#ifndef NULL
#define NULL 0
#endif

/* 6502 Flags */
#define FLAG_C 0x01
#define FLAG_Z 0x02
#define FLAG_I 0x04
#define FLAG_D 0x08
#define FLAG_B 0x10
#define FLAG_R 0x20
#define FLAG_V 0x40
#define FLAG_N 0x80


/* Interrupt Vectors */
#define VECTOR_NMI   0xfffa
#define VECTOR_RESET 0xfffc
#define VECTOR_IRQ   0xfffe
#define NMI_REQ  	CPU->NMI_State = 0;// NMI Request
#define IRQ_REQ  	CPU->IRQ_State = 0;// IRQ Request
#define BASE_STACK   0x100/* Stack Address */


typedef struct // Value and Flag Data
{
  BYTE byValue;
  BYTE byFlag;
}value_table;

typedef struct // Value and Flag Data
{
// 6502 Register
    WORD PC;
    BYTE SP;
    BYTE F;
    BYTE A;
    BYTE X;
    BYTE Y;
    BYTE IRQ_State;// The state of the IRQ pin
    BYTE IRQ_Wiring;// Wiring of the IRQ pin
    BYTE NMI_State;// The state of the NMI pin
    BYTE NMI_Wiring;// Wiring of the NMI pin
    WORD g_wPassedClocks;// The number of the clocks that it passed
    BYTE g_byTestTable[ 256 ];// A table for the test
    value_table g_ASLTable[ 256 ];// A table for ASL
    value_table g_LSRTable[ 256 ];// A table for LSR
    value_table g_ROLTable[ 2 ][ 256 ];// A table for ROL
    value_table g_RORTable[ 2 ][ 256 ];// A table for ROR
}CpuResource;






// Emulator Operation
void K6502_Init(void);
void K6502_Reset(void);
void K6502_Set_Int_Wiring( BYTE byNMI_Wiring, BYTE byIRQ_Wiring );
void K6502_Step( register WORD wClocks );

// I/O Operation (User definition)

static __inline BYTE K6502_Read( WORD wAddr);
static __inline WORD K6502_ReadW( WORD wAddr );
static __inline WORD K6502_ReadW2( WORD wAddr );
static __inline BYTE K6502_ReadZp( BYTE byAddr );
static __inline WORD K6502_ReadZpW( BYTE byAddr );
static __inline BYTE K6502_ReadAbsX(void);
static __inline BYTE K6502_ReadAbsY(void);
static __inline BYTE K6502_ReadIY(void);

static __inline void K6502_Write( WORD wAddr, BYTE byData );
static __inline void K6502_WriteW( WORD wAddr, WORD wData );


// The state of the IRQ pin
//extern BYTE IRQ_State;

// The state of the NMI pin
//extern BYTE NMI_State;

// The number of the clocks that it passed
extern WORD g_wPassedClocks;
extern CpuResource *CPU;

#ifdef	__cplusplus
}
#endif

#endif /* !K6502_H_INCLUDED */
